package cn.meibang.aggragation.meibanguserskillstype.controller;

import cn.apestar.agg.common.security.BaseAuthController;
import cn.apestar.core.base.BaseMessage;
import cn.meibang.meibanguserskillstype.api.IMeibangUserSkillsTypeAPIService;
import cn.meibang.meibanguserskillstype.provider.request.ListMeibangUserSkillsTypeRequest;
import cn.meibang.meibanguserskillstype.provider.request.MeibangUserSkillsTypeRequest;
import cn.meibang.meibanguserskillstype.provider.response.MeibangUserSkillsTypeResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 技师技能类型 <br>
 * 详细说明.
 * <p>
 *
 * @author yudw
 * @version 1.0
 */
@RestController
@RequestMapping("/meibang/meibanguserskillstype")
public class MeibangUserSkillsTypeController extends BaseAuthController {

    private Logger logger = LoggerFactory.getLogger(MeibangUserSkillsTypeController.class);

    @Autowired
    private IMeibangUserSkillsTypeAPIService meibanguserskillstypeService;

    /**
     * 新增技师技能类型
     *
     * @param request
     */
    @RequestMapping(value = "/addorUpdate", method = RequestMethod.POST)
    public Object create(@RequestBody @Valid MeibangUserSkillsTypeRequest request) {
        meibanguserskillstypeService.addorUpdate(request);
        return new BaseMessage();
    }

    /**
     * 删除技师技能类型
     *
     * @param id
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
    public Object del(@PathVariable("id") Long id) {
        meibanguserskillstypeService.del(id);
        return new BaseMessage();
    }

    /**
     * 查询技师技能类型
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/lisForPage", method = RequestMethod.POST)
    public List<MeibangUserSkillsTypeResponse> lisForPage(@RequestBody ListMeibangUserSkillsTypeRequest request) {
        List list = meibanguserskillstypeService.lisForPage(request);
        return list;
    }

    /**
     * 查询技师技能类型
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public List<MeibangUserSkillsTypeResponse> list(@RequestBody MeibangUserSkillsTypeRequest request) {
        List list = meibanguserskillstypeService.list(request);
        return list;
    }

    /**
     * 查询技师技能明细类型
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public MeibangUserSkillsTypeResponse get(@PathVariable("id") Long id) {
        MeibangUserSkillsTypeRequest request = new MeibangUserSkillsTypeRequest();
        List<MeibangUserSkillsTypeResponse> list = meibanguserskillstypeService.list(request);
        if (list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    /**
     * 查询技师技能明细类型
     *
     * @return
     */
    @RequestMapping(value = "getMySkills", method = RequestMethod.GET)
    public MeibangUserSkillsTypeResponse getMySkills() {
        return meibanguserskillstypeService.getByUserId(getCurrentUserId());
    }
}